package com.design_pattern._02_structure._01_detector;

/**
 * 装饰器，与具体装饰类
 */
public abstract class NoodlesDecorator implements INoodles {

    private final INoodles noodles;    //添加一个INoodles 的引用

    public NoodlesDecorator(INoodles noodles) {     //通过构造器来设置INoodles
        this.noodles = noodles;
    }

    @Override
    public void cook() {
        if (noodles != null) {
            noodles.cook();
        }
    }

}

class EggDecorator extends NoodlesDecorator {

    public EggDecorator(INoodles noodles) {
        super(noodles);
    }

    @Override
    public void cook() {
        System.out.println("加了一个荷包蛋");
        super.cook();
    }
}

class BeefDecorator extends NoodlesDecorator {

    public BeefDecorator(INoodles noodles) {
        super(noodles);
    }

    @Override
    public void cook() {
        System.out.println("加了一斤牛肉");
        super.cook();
    }
}